﻿@model Bricks.Site.Models.OrgInfo.OrgChooseView

@{
    ViewBag.Title = "选择机构";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<script type="text/javascript">
    $(function () {
        //当页面首次刷新的时候执行的事件
        initTreeTable();
    });
    //实现对DataGird控件的绑定操作

    function initTreeTable(queryData) {
        $('#orgChooseTreeGrid').treegrid({   //定位到Table标签，Table标签的ID是myTreeGrid
            //   OrgInfo是控制器，GetData是控制器中获取用户数据的一个Action
            url: '/OrgInfo/GetDataList?exceptAll=True',   //指向后台的Action来获取当前用户的信息的Json格式的数据
            //title: '机构管理',  //标识
            //iconCls: 'icon-user',
            //width: 'auto',
            //height: 500,
            nowrap: true,
            autoRowHeight: false,
            singleSelect: false,
            striped: true,
            collapsible: true,
            pagination: false,
            rownumbers: true,
            //sortName: 'ID',    //根据某个字段给easyUI排序
            //sortOrder: 'asc',
            remoteSort: false,
            idField: 'ID',
            treeField: 'OrgName',
            parentField: 'PID',
            queryParams: queryData,  //异步查询的参数
            //toolbar: '#myTreeToolBar',
            columns: [[
                { field: 'ck', checkbox: true },   //选择
                { title: '@Html.LabelFor(model => model.OrgName)', field: 'OrgName', width: 165, sortable: false },
            ]],
            //onLoadSuccess: ChooseOrg.SelectedOrg  //成功加载数据后选中记录
            //数据加载成功之后触发
            onLoadSuccess: function () {
                var orgIDs = $("#hOrgIDs").val();
                //$.EasyuiMsg(orgIDs);  //弹出测试
                var orgIDList = orgIDs.split(',');  //将string转为string数组（按,分隔）
                if (orgIDList.length > 0) {
                    for (var i = 0; i < orgIDList.length; i++) {
                        $('#orgChooseTreeGrid').treegrid('select', orgIDList[i]);  //选中对应的树节点
                    }
                }
            },
            //当用户点击一个节点时触发
            onClickRow: function () {
                var orgIDs = "";
                var selectedOrgList = $('#orgChooseTreeGrid').datagrid('getSelections');  //获取列表数据
                if (selectedOrgList.length > 0) {
                    for (var i = 0; i < selectedOrgList.length; i++) {
                        if (orgIDs.length == 0)
                            orgIDs = selectedOrgList[i].ID;
                        else
                            orgIDs = orgIDs + "," + selectedOrgList[i].ID;
                    }
                }
                //$("#hOrgIDs").val() = orgIDs;
                document.getElementById("hOrgIDs").value = orgIDs;  //给隐藏域字段赋值
            },
            onClickCell: function () {
                var orgIDs = "";
                var selectedOrgList = $('#orgChooseTreeGrid').datagrid('getSelections');  //获取列表数据
                if (selectedOrgList.length > 0) {
                    for (var i = 0; i < selectedOrgList.length; i++) {
                        if (orgIDs.length == 0)
                            orgIDs = selectedOrgList[i].ID;
                        else
                            orgIDs = orgIDs + "," + selectedOrgList[i].ID;
                    }
                }
                //$("#hOrgIDs").val() = orgIDs;
                document.getElementById("hOrgIDs").value = orgIDs;  //给隐藏域字段赋值
            }
        });
        }
        var ChooseOrg = {
            //选中传过来的已选择机构
            //SelectedOrg: function () {
            //    //var node = $('#orgChooseTreeGrid').treegrid('find', "83f49133-db46-4fbb-8895-387fba072a80");
            //    //$('#orgChooseTreeGrid').treegrid('select', node.target);

            //    var node = $('#orgChooseTreeGrid').treegrid('select', "83f49133-db46-4fbb-8895-387fba072a80");
            //}
        }
</script>

<div class="easyui-panel" title="机构列表">
    <form id="form-chooseOrg" method="post">
        <table id="orgChooseTreeGrid" style="height: 350px"></table>
    </form>
</div>
<input type="hidden" id="hOrgIDs" value="@ViewBag.OrgIDs" />
